<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // navigator  ->  设备相关的信息 (window.navigator)
    // console.log(navigator);


    // 属性:
    // userAgent  用户代理信息，通过该属性可以获取浏览器及操作系统信息

    // PC:  Windows  Mac
    // app: iPhone  Android  BB10  iPad

    // console.log(navigator.userAgent); //"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"

    // console.log(navigator.userAgent);

    // 判断设备类型 -> 是否是移动端

    var appList = ["iPhone", "Android", "BB10", "iPad"];

    var userAgent = navigator.userAgent;  // 用户代理信息 (字符串)

    // 判断是否是移动端?

    var flag = false;// 假设不是移动端

    for(var i=0;i<appList.length;i++){
        var app = appList[i];
        var reg = new RegExp(app,"i");

        // userAgent.toLowerCase().includes(app.toLowerCase())
        if(userAgent.search(reg)!=-1){
            flag = true;
            break;
        }

    }
    if(flag){
        console.log("移动端",app);
    }else{
        console.log("PC端");
    }








</script>

</html>